<?php
/**
 * Created by PhpStorm.
 * User: YongXuan.Huang
 * Date: 2017/10/1
 * Time: 20:38
 */


namespace Common\Common;

class Catalogue
{
    /**
     * 递归创建
     *
     * @param $dir
     * @return bool
     */
    public static function makeDirectory($dir)
    {
        return is_dir($dir) or self::makeDirectory(dirname($dir)) and mkdir($dir, 0777);
    }

    /**
     * 删除文件夹 包括里面的子文件和目录
     * @param $path
     */
    public static function removeDirectory($path)
    {
        $files = scandir($path);
        foreach ($files as $key => $value) {
            if ($value === '.' || $value === '..') {
                continue;
            }
            $file = $path . DIRECTORY_SEPARATOR . $value;
            if (is_file($file)) {
                unlink($file);
                continue;
            }
            if (is_dir($file)) {
                self::removeDirectory($file);
            }
        }
        rmdir($path);
    }
}